package com.example.restaurantclient.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.restaurantclient.Bubble.BadgeView;
import com.example.restaurantclient.Entities.News;
import com.example.restaurantclient.R;


import java.util.ArrayList;
import java.util.List;

public class CustomNewsAdapter extends BaseAdapter {
    //
    private Context context;
    private List<News> newItems = new ArrayList<>();
    private int res;
    private BadgeView bv1;

    public CustomNewsAdapter(Context context, List<News> newItems, int res) {
        this.context = context;
        this.newItems = newItems;
        this.res = res;
    }

    @Override
    public int getCount() {
        if (newItems != null) {
            return newItems.size();//获得数据的条数
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (newItems != null) {
            return newItems.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        //加载布局文件
        LayoutInflater inflater = LayoutInflater.from(context);
        convertView = inflater.inflate(res, null);
        System.out.println("大小11：//" + newItems.size());
        //获取控件
        ImageView imageView = convertView.findViewById(R.id.news_store_picture);
        TextView name = convertView.findViewById(R.id.news_store_name);
        TextView date = convertView.findViewById(R.id.news_date);
        TextView time = convertView.findViewById(R.id.news_time);
        TextView info = convertView.findViewById(R.id.news_text);

//        imageView.setImageBitmap(newItems.get(position).get);
        name.setText(newItems.get(position).getStore());
        date.setText(newItems.get(position).getDate());
        time.setText(newItems.get(position).getTime());
        info.setText(newItems.get(position).getNewsText());
        if(newItems.get(position).isFlag()==false){
            bv1=new BadgeView(context);
            bv1.setBindView(imageView);

//        bv1.setTextColor(context.getResources().getColor(R.color.colorWhite));
            bv1.setBadgeLayoutParams(8,8);
//        bv1.setTextSize(6);
        }


        return convertView;
    }

}
